﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management.Automation;

namespace LinqToPowershell
{
    [Cmdlet("Trace", "PSToken")]
    public class TracePSTokenCmdlet : Cmdlet
    {
        [Parameter(Mandatory=true, Position=0)]
        public ScriptBlock ScriptBlock;

        protected override void ProcessRecord()
        {
            System.Collections.ObjectModel.Collection<PSParseError> errors;
            var tokens = PSParser.Tokenize(ScriptBlock.ToString(), out errors);

            if (errors == null || errors.Count == 0)
            {
                WriteObject(tokens);
            }
            else
            {
                WriteObject(errors);
            }
        }
    }
}
